var win = Titanium.UI.currentWindow;
win.backgroundColor = '#B6CCDD';
var img = Ti.UI.createButton({
	title: 'Images' ,
	 top:25,
});
win.add(img);

img.addEventListener('click', function(){
	Ti.Media.openPhotoGallery({
 
        success:function(event) {
            var image = event.media;
            alert('picture was selected');
        },
        cancel:function() { alert('canceled');},
        error:function(error) {
            Titanium.UI.createAlertDialog({title:'Error', message:'...'}).show();
        },
        arrowDirection:  Ti.UI.iPad.POPOVER_ARROW_DIRECTION_UP,
        popoverView:'label'
        //showControls:true,
        //mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
    });
});

var vdo = Ti.UI.createButton({
	title: 'Videos' ,
	top:100,
});
win.add(vdo);


vdo.addEventListener('click', function(){
Titanium.Media.showCamera({
    success:function(event)
    {
        var image = event.media;
        if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
        {
 
            var imageView = Ti.UI.createImageView({width:148,height:148,image:event.media,top:200,left:70});
            win.add(imageView);  
        }
        else
        {
            // alert user that video is not supported
        }
    },
    cancel:function()
    {
               // do nothing
    },
    error:function(error)
    {
        // create alert
        var a = Titanium.UI.createAlertDialog({title:'Camera'});
 
        // set message
        if (error.code == Titanium.Media.NO_CAMERA)
        {
            a.setMessage('Camera Not Found');
        }
        else
        {
            a.setMessage('Unexpected error: ' + error.code);
        }
        a.show();
    },
    saveToPhotoGallery:true,
    allowEditing:true,
    mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
    });
});

var text = Ti.UI.createButton({
	title: 'Text' ,
	 top:175,
});
win.add(text);


 



